package com.egg.auth.feign.fallback;

import com.egg.auth.feign.AuthUserFeignClient;
import com.egg.auth.model.LoginUserInfo;
import com.egg.auth.model.request.web.UserPagePostFeign;
import com.egg.auth.model.response.web.UserPage;
import com.egg.common.core.enums.ResponseCode;
import com.egg.common.core.model.response.PageData;
import com.egg.common.core.model.response.ResponseData;
import feign.hystrix.FallbackFactory;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * feignClient降级
 *
 * @author east
 */
@Slf4j
@Configuration
public class AuthUserFeignClientFallback implements FallbackFactory<AuthUserFeignClient> {


    @Override
    public AuthUserFeignClient create(Throwable cause) {
        return new AuthUserFeignClient() {

            @Override
            public ResponseData<PageData<UserPage>> userPagePost(UserPagePostFeign param) {
                ResponseData res = new ResponseData<>();
                res.setCode(ResponseCode.FALLBACK_ERROR.getCode());
                res.setMsg(ResponseCode.FALLBACK_ERROR.getMessage());
                return res;
            }

            @Override
            public ResponseData<LoginUserInfo> userLoginInfoByToken(
                    @ApiParam(value = "令牌", required = true) @RequestParam(value = "token") String token
            ) {
                ResponseData res = new ResponseData<>();
                res.setCode(ResponseCode.FALLBACK_ERROR.getCode());
                res.setMsg(ResponseCode.FALLBACK_ERROR.getMessage());
                return res;
            }

        };

    }


}
